<!--
 * @description  : 案件-文书列表-验证案件是否需要填写补录申请书 canAddClearing
 * @descriptionDetail: 案件-文书列表
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-08-25 15:43:11
-->

<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view class="content official-content">
      <!-- 案件基本信息 -->
      <view class="base-info">
        <view class="mini-title gray1">
          案发时间： {{ $u.test.isEmpty(baseInfo.caseDate) ? "案发时间未录入" : baseInfo.caseDate }}
        </view>
        <view class="code-content">
          <view class="code-text">
            {{ baseInfo.caseCode }}
          </view>
          <u-button plain size="mini" class="btn-lay" type="primary" @click="caseView()">
            <u-icon name="edit-pen" size="34"></u-icon>基础信息
          </u-button>
        </view>
        <view class="addr-lay">
          <view>{{ $u.test.isEmpty(baseInfo.casePlace) ? "案发地址未录入" : baseInfo.casePlace }}</view>
          <view>{{ $u.test.isEmpty(baseInfo.party) ? "当事人未录入" : baseInfo.party }}</view>
        </view>
        <view class="reason-lay">
          案由：{{ $u.test.isEmpty(baseInfo.caseOfAction) ? "未录入" : baseInfo.caseOfAction }}
        </view>
        <view class="reason-lay">
          承办人：{{ $u.test.isEmpty(baseInfo.undertaker) ? "未录入" : baseInfo.undertaker }}
        </view>
      </view>
      <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color" style="margin: 0px -16px;"></u-gap>
      <!-- 案件文书信息 -->
      <view class="official-info">
        <view class="off-info-item" v-for="(item, index) in dataList" :key="index">
          <view class="off-info-title">
            <view style="width: calc(60%);">
              <form-section :chose-type="choseType" :title="item.itemName"></form-section>
            </view>
            <view class="right-box" v-show="!justView">
              <u-icon v-if="choseType !== 'caseMap'" name="plus-circle" :color="$theme.u_type_primary" label="添加" label-size="26"
                :label-color="$theme.u_type_primary" size="40" @click="addAdvance(item)"></u-icon>
            </view>
          </view>
          <view v-if="choseType === 'caseMap'">
            <u-swipe-action :show="doc.show" :index="index + '-' + i" :disabled="doc.disabled || justView"
                            v-for="(doc, i) in item.docList" :key="'doc' + i" @click="docRemove" @open="offOpen">
              <view class="off-info-content off-tb">
                <view @click="toDetailOfficial(item, doc)">
                  <view class="off-tb">
                    <!-- 1201 已完成 -->
                    <u-icon name="checkmark-circle-fill" :label="doc.docName" color="#19be6b" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.DONE"></u-icon>
                    <!-- 1202 进行中 -->
                    <u-icon name="clock-fill" :label="doc.docName" :color="$theme.u_type_primary" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.HAVE_HAND"></u-icon>
                    <!-- 1203 未开始状态-->
                    <u-icon name="circleyuanquan" custom-prefix="csbi-icon" :label="doc.docName" color="#f95e5a" size="34"
                            v-if="doc.handleStatus == DOC_STATUS.NOT_STAR"></u-icon>
                    <!-- 1209 已退回状态-->
                    <u-icon name="clock-fill" :label="doc.docName" color="#fa3534" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.BACK"></u-icon>
                    <u-icon name="account-fill" color="#929292" size="36" :label="doc.operator" label-size="26"
                            v-if="doc.operator"></u-icon>
                  </view>
                  <view class="off-date">
                    {{ doc.docCodeTitle }}
                  </view>
                  <view class="off-date">
                    {{ doc.docStartTime }}
                  </view>
                  <view class="off-date" v-if="doc.isHaveFlow">
                    <view v-for="(flow, f) in doc.flows" :key="'flow' + f">
                      <text v-if="flow.isCurrent">
                        当前环节：<text class="text-sty">
                        {{ flow.simpleName }}
                      </text>
                      </text>
                    </view>
                  </view>
                </view>
                <!-- 附件上传 v-show="doc.scan != 0" -->
                <view class="sub-img u-p-r-20">
                  <!-- scan为1，表示有图片，显示绿色图标 -->
                  <u-image width="18px" height="18px" v-if="doc.scan" src="/static/case/img_green.png" mode="widthFix"
                           @click="submitImage(doc)">
                  </u-image>
                  <!-- scan为0 表示无图片，isPicUploadable为true，表示可以上传图片，显示灰色图标 -->
                  <u-image width="18px" height="18px" v-if="!doc.scan && doc.isPicUploadable"
                           src="/static/case/img_gray.png" mode="widthFix" @click="submitImage(doc)">
                  </u-image>
                  <!-- 临时注释掉mengchen -->
                  <view style="margin-left: 15px;"
                        v-if="signViewUrl && doc.isFinish && CASE_DOC_NAME_PATH[doc.docCode] && CASE_DOC_NAME_PATH[doc.docCode].isSign"
                        @click="handleShare(doc)">
                    <u-icon v-if="docSign[doc.docInsUuid]" name="share" :color="$theme.u_type_primary" size="28"></u-icon>
                    <u-icon v-else name="share" :color="$theme.u_type_success" size="28"></u-icon>
                  </view>
                  <view style="margin-left: 15px;" v-if="doc.docCode == 'docLocalePunish' && sendPayIconShow">
                    <u-image width="18px" height="18px" src="/static/case/plane-blue.png" mode="widthFix"
                             @click="handleSendPay">
                    </u-image>
                  </view>
                  <view style="margin-left: 15px;" v-if="doc.isEleDeliver == '1' || doc.isEleDeliver == 1">
                    <u-image width="18px" height="18px" src="/static/case/ele_deliver.png" mode="widthFix"
                             @click="sendEleDeliver(doc)">
                    </u-image>
                  </view>
                </view>
              </view>
            </u-swipe-action>
          </view>
          <view v-else>
            <u-swipe-action :show="doc.show" :index="index + '-' + i" :options="options" :disabled="doc.disabled || justView"
                            v-for="(doc, i) in item.docList" :key="'doc' + i" @click="docRemove" @open="offOpen">
              <view class="off-info-content off-tb">
                <view @click="toDetailOfficial(item, doc)">
                  <view class="off-tb">
                    <!-- 1201 已完成 -->
                    <u-icon name="checkmark-circle-fill" :label="doc.docName" color="#19be6b" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.DONE"></u-icon>
                    <!-- 1202 进行中 -->
                    <u-icon name="clock-fill" :label="doc.docName" :color="$theme.u_type_primary" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.HAVE_HAND"></u-icon>
                    <!-- 1203 未开始状态-->
                    <u-icon name="circleyuanquan" custom-prefix="csbi-icon" :label="doc.docName" color="#f95e5a" size="34"
                            v-if="doc.handleStatus == DOC_STATUS.NOT_STAR"></u-icon>
                    <!-- 1209 已退回状态-->
                    <u-icon name="clock-fill" :label="doc.docName" color="#fa3534" size="40"
                            v-if="doc.handleStatus == DOC_STATUS.BACK"></u-icon>
                    <u-icon name="account-fill" color="#929292" size="36" :label="doc.operator" label-size="26"
                            v-if="doc.operator"></u-icon>
                  </view>
                  <view class="off-date">
                    {{ doc.docCodeTitle }}
                  </view>
                  <view class="off-date">
                    {{ doc.docStartTime }}
                  </view>
                  <view class="off-date" v-if="doc.isHaveFlow">
                    <view v-for="(flow, f) in doc.flows" :key="'flow' + f">
                      <text v-if="flow.isCurrent">
                        当前环节：<text class="text-sty">
                        {{ flow.simpleName }}
                      </text>
                      </text>
                    </view>
                  </view>
                </view>
                <!-- 附件上传 v-show="doc.scan != 0" -->
                <view class="sub-img u-p-r-20">
                  <!-- scan为1，表示有图片，显示绿色图标 -->
                  <u-image width="18px" height="18px" v-if="doc.scan" src="/static/case/img_green.png" mode="widthFix"
                           @click="submitImage(doc)">
                  </u-image>
                  <!-- scan为0 表示无图片，isPicUploadable为true，表示可以上传图片，显示灰色图标 -->
                  <u-image width="18px" height="18px" v-if="!doc.scan && doc.isPicUploadable"
                           src="/static/case/img_gray.png" mode="widthFix" @click="submitImage(doc)">
                  </u-image>
                  <!-- 临时注释掉mengchen -->
                  <view style="margin-left: 15px;"
                        v-if="signViewUrl && doc.isFinish && CASE_DOC_NAME_PATH[doc.docCode] && CASE_DOC_NAME_PATH[doc.docCode].isSign"
                        @click="handleShare(doc)">
                    <u-icon v-if="docSign[doc.docInsUuid]" name="share" :color="$theme.u_type_primary" size="28"></u-icon>
                    <u-icon v-else name="share" :color="$theme.u_type_success" size="28"></u-icon>
                  </view>
                  <view style="margin-left: 15px;" v-if="doc.docCode == 'docLocalePunish' && sendPayIconShow">
                    <u-image width="18px" height="18px" src="/static/case/plane-blue.png" mode="widthFix"
                             @click="handleSendPay">
                    </u-image>
                  </view>
                  <view style="margin-left: 15px;" v-if="doc.isEleDeliver == '1' || doc.isEleDeliver == 1">
                    <u-image width="18px" height="18px" src="/static/case/ele_deliver.png" mode="widthFix"
                             @click="sendEleDeliver(doc)">
                    </u-image>
                  </view>
                </view>
              </view>
            </u-swipe-action>
          </view>
        </view>
      </view>
      <!-- 文书 弹出层 -->
      <view class="">
        <u-action-sheet :list="sheetList" v-model="actionSheetShow" @click="sheetClick"></u-action-sheet>
      </view>
    </view>
    <u-popup v-model="qrcodeShow" mode="bottom" height="70%" @close="qrcodeShow = false">
      <view class="qrcodeContainer">
        <img :src="qrcodeImg" alt="暂无图片" />
        <p>请扫码签名</p>
      </view>
    </u-popup>
    <!-- 选择签名当事人 -->
    <u-action-sheet :list="dsrList" v-model="dsrSelectShow" @click="dsrSelectConfirm"></u-action-sheet>
    <!-- 电子送达 -->
    <u-popup v-model="eleShow" mode="bottom" height="55%" @close="eleShow = false">
      <ele-deliver-component :deliverEleList="deliverEleList" :docInfo="eleDoc"
        @close="eleClose"></ele-deliver-component>
    </u-popup>
  </view>
</template>

<script>
import commonService from '@/service/common/common.service';
import caseService from '@/service/case/case.service.js';
import officeService from "@/service/case/office.service.js";
import FormSection from "@/components/form-section.vue";
import EleDeliverComponent from "../../commonPage/eleDeliverComponent.vue";
import {
  DOC_STATUS,
  CASE_DOC_NAME_PATH,
  CASE_TYPE,
} from "@/service/case/mapping/index.js";
import QRCode from 'qrcode';

export default {
  components: {
    FormSection,
    EleDeliverComponent,
  },
  data() {
    return {
      eleShow: false,
      deliverEleList: [],
      eleDoc: {},
      DOC_STATUS,
      CASE_DOC_NAME_PATH,
      CASE_TYPE,
      actionSheetShow: false,
      userInfo: {}, // 登录人信息
      // isSchedule: false, // 是否快办试运行
      prevParams: {}, // 列表页面传过来的参数
      simpleDocCode: ['docLocalePunish', 'docLocalCheckRecord', 'docCheckRecord', 'docEvidCopy', 'docPaymentNote',], // 简易文书code
      generalDocCode: ['docGoodsApv', 'docGoodsReg', 'docGoodsHandle', 'docCheckRecord', 'docEvidCopy', 'docInquiryNotice', 'docPriceAudit',
        'docAskRecord', 'docSurveyHandle', 'zmSampling', 'docServiceConfirm', 'docSampleGoodsApproval', 'docLawlessnessCigar', 'docSampleHandle', 'docReplenishment',
      ], // 普通文书code  'docQuickConfirm',
      caseReaultInfo: {}, // 点击添加按钮存放的数据
      baseInfo: {},
      sheetList: [], // 弹框数据
      selectList: [],
      dataList: [],
      evidenceList: [], // 证据列表数据
      handleProc: CASE_TYPE.SIMPLE, // 简易案件编码
      options: [{
        text: '删除',
        style: {
          backgroundColor: '#dd524d',
        },
      },],
      itemsList: [], // 文书环节数据
      qrcodeShow: false,  // 二维码是否显示
      qrcodeImg: "",
      dsrList: [],    // 待签名当事人
      dsrSelectShow: false,
      docIns: null, // 当前选中的文书
      docSign: {},  // 文书第三方签名情况
      signViewUrl: null,  // 第三方签名地址
      sendPayIconShow: false, // 当场处罚决定书是否显示发送缴费单按钮
      decideUuid: '',
      disabled: false,
      choseType: ''
    }
  },
  computed: {
    justView() {
      try {
        let ar = this.baseInfo.isLookList;
        if (this.baseInfo.handleProc == CASE_TYPE.NORMAL) {
          return ar[0] == '0';
        } else {
          return false;
        }
      } catch (e) {
        console.log(e);
        return false;
      }
    },
  },
  watch: {
    dataList(newValue) {
      let self = this;
      if (newValue) {
        newValue.filter(item => {
          item.docList.filter(doc => {
            self.$set(doc, 'show', false);
            self.$set(doc, 'disabled', false);
            if (doc.docCode == 'docGoodsApv' || doc.docCode == 'docGoodsReg') {
              self.$set(doc, 'disabled', true);
            }
          });
          return true;
        });
        // 查询当前文书是否已完成第三方签名
        this.dataList.forEach(dl => {
          dl.docList && dl.docList.forEach(d => {
            this.searchIsSigned(d.docInsUuid).then(s => this.$set(this.docSign, d.docInsUuid, s));
          });
        });
      }
    },
  },
  mounted() {

  },
  onLoad() {
    let prevParams = this.$u.deepClone(this.getRouteParam());

    if (prevParams.type && prevParams.type === 'view') {
      try {
        this.prevParams = prevParams.param;
        this.baseInfo = this.prevParams ? this.prevParams : {};
        this.choseType = 'caseMap';
      } catch (e) {
        console.log(e);
      }
      // 查询配置的第三方签名地址
      commonService.getThirdSign().then(ud => {
        if (ud.success) {
          this.signViewUrl = ud.data?.filter(d => d.configSubKey === 'viewUrl')[0]?.configValue;
        }
      });
    } else {
      try {
        this.prevParams = this.$u.deepClone(this.getRouteParam());
        this.baseInfo = this.prevParams ? this.$u.deepClone(this.prevParams) : {};
      } catch (e) {
        console.log(e);
      }
      // 查询配置的第三方签名地址
      commonService.getThirdSign().then(ud => {
        if (ud.success) {
          this.signViewUrl = ud.data?.filter(d => d.configSubKey === 'viewUrl')[0]?.configValue;
        }
      });
    }
  },
  onShow() {
    caseService.getCaseInfoById({
      caseUuid: this.baseInfo.caseUuid,
    }).then(res => {
      if (res.success) {
        this.objMerge(this.baseInfo, res.bean);
      }
      caseService.casePropertyList().then(res => {
        this.$modal.hideLoading();
        if (!res.success) {
          return;
        }
        if (res.data && res.data.length > 0) {
          let defaultCaseClue = res.data[0];
          if (this.baseInfo.handleProc == CASE_TYPE.SIMPLE && this.$u.test.isEmpty(this.baseInfo
            .caseOfAction)) {
            this.baseInfo.caseOfAction = defaultCaseClue.caseProperty;
            this.baseInfo.casePropertyRelList = [];
            defaultCaseClue.isMain = true;
            defaultCaseClue.caseUuid = this.baseInfo.caseUuid;
            this.baseInfo.casePropertyRelList.push(defaultCaseClue);
          } else {
            if (this.baseInfo.casePropertyRelList && this.baseInfo.casePropertyRelList
              .length > 0) {
              let orginalCaseClueList = [];
              for (let i = 0; i < this.baseInfo.casePropertyRelList.length; i++) {
                let op = this.baseInfo.casePropertyRelList[i];
                for (let j = 0; j < res.data.length; j++) {
                  if (res.data[j].casepropUuid == op.casepropUuid) {
                    let opx = res.data[j];
                    this.objMerge(opx, op);
                    opx.caseUuid = op.caseUuid;
                    opx.isMain = op.isMain;
                    orginalCaseClueList.push(opx);
                    break;
                  }
                }
              }
              this.baseInfo.casePropertyRelList = [...orginalCaseClueList,];
            }
          }
        }
      }).catch(err => {
        console.log("查询失败:" + err);
      });
    }).catch(res => {
      console.log(res.msg);
    });
    this.initDocList();
  },
  methods: {
    // 获取文书列表数据
    initDocList() {
      this.$modal.showLoading('加载中');
      let self = this;
      officeService.itemsMobile({
        bizUuid: this.prevParams.caseUuid,
        handProc: this.prevParams.handleProc,
      }).then(res => {
        if (res.success) {
          this.itemsList = res.data;
          caseService.getCaseDocList({
            bizUuid: this.prevParams.caseUuid,
            type: 'case',
          }).then(res => {
            self.$modal.hideLoading();
            if (res) {
              // 文书列表数据处理
              let [docList, stageDocs,] = [res.data, [],];
              // 过滤已删除的文书
              docList = docList.filter(item => item.handleStatus !== DOC_STATUS
                .DEL_DONE);

              docList.forEach((v, i) => {
                let filterCode = this.prevParams.handleProc === this
                  .handleProc ? this.simpleDocCode : this.generalDocCode;
                if (filterCode.includes(v.docCode)) {
                  let docStage = stageDocs.filter(r => r.itemUuid === v
                    .itemUuid);
                  if (!docStage || docStage.length == 0) {
                    let newV = {};
                    Object.assign(newV, v);
                    v.docList = [];
                    v.docList.push(newV);
                    stageDocs.push(v);
                  } else {
                    docStage[0].docList.push(v);
                  }
                }
                // 判断是否有已完成的行政处罚
                if (v.docCode == 'docLocalePunish' && v.handleStatus == DOC_STATUS.DONE) {
                  // 调用接口
                  this.decideUuid = v.docInsUuid;
                  this.getLocalePunish();
                }
              });
              // 循环文书环节
              this.itemsList.forEach((item) => {
                let lst = stageDocs.filter(s => s.itemUuid === item.itemUuid);
                if (lst.length == 0) {
                  //if (item.itemUuid != 'item-01') {
                    stageDocs.push({
                      itemUuid: item.itemUuid,
                      itemName: item.itemName,
                      titemUuid: item.titemUuid,
                      docList: [],
                    })
                  //}
                }
              })
              stageDocs.sort((a, b) => {
                let idxNo = parseInt(a.itemUuid.replace('item-', ''), 10);
                let idxNo2 = parseInt(b.itemUuid.replace('item-', ''), 10);
                return idxNo - idxNo2;
              });
              console.log(stageDocs, 'stageDocs');
              this.dataList = stageDocs;
            } else {
              self.$u.toast(res);
            }
          })
        }
      }).catch(err => {
        self.$modal.hideLoading();
        self.$u.toast(err);
      });
    },
    // 弹出选择sheet
    addAdvance(list) {
      this.caseReaultInfo = {};
      this.caseReaultInfo = list;
      this.$u.loading("加载中...");
      caseService.getDocConfigList({
        itemUuid: list.itemUuid,
      }).then(res => {
        this.$u.hideLoading();
        if (!res || res.data.length == 0) {
          return false;
        }
        this.selectList = res.data;
        this.btnSheetHandler(list, res.data);
      }).catch((err) => {
        this.$u.hideLoading();
        this.$u.toast(err)
      })
    },
    // 按钮事件处理
    btnSheetHandler(stage, cfgs) {
      this.sheetList = [];
      cfgs.map((cfg, idx) => {
        let [code, regisCode, obj,] = [cfg.docCode, ['docGoodsApv', 'docGoodsReg',
          'docGoodsHandle',], {},
        ];
        let codeList = this.prevParams.handleProc === this.handleProc ? this.simpleDocCode : this
          .generalDocCode;
        console.log('---------3333----', codeList)
        let evideCode = codeList.filter(e => {
          return regisCode.indexOf(e) == -1
        });
        // 操作菜单条件判断
        // let flag = (stage.itemName === '立案' && evideCode.indexOf(code) != -1) || (stage.itemName === '先行登记' && regisCode.indexOf(code) != -1) || (stage.itemName === '调查取证' && evideCode.indexOf(code) != -1) || (stage.itemName === 'simple-item-01-01' && code === 'docCheckRecord') || (stage.itemName === '鉴定核价' && evideCode.indexOf(code) != -1);
        let flag = evideCode.indexOf(code) != -1 || (stage.itemName === '先行登记' && regisCode.indexOf(
          code) != -1) || (stage.itemName === 'simple-item-01-01' && code === 'docCheckRecord') || (stage.itemName === '立案' && evideCode.indexOf(code) != -1);
        if (flag) {
          obj['text'] = cfg.docName;
          obj['docCode'] = cfg.docCode;
          obj['docUuid'] = cfg.docUuid;
          obj['titemUuid'] = stage.titemUuid;
          this.sheetList.push(obj);
        }
      });
      this.actionSheetShow = true;
    },

    //验证案件是否需要填写补录申请书
    async  canAddClearing(caseUuid) {
      let isPas = true ;
      await  caseService.canAddClearingGX(this.prevParams.caseUuid).then(res => {
          if (res.success) {
            isPas = true;
          } else {
            this.$u.toast(res.msg)
            isPas =  false;
          }
      });
      return isPas;
    },



// 弹层点击事件
    async sheetClick(index) {

      let [obj, quickCode,] = [this.sheetList[index],
      ['docQuickNotice', 'docQuickConfirm', 'docCheckAskRecord',],
      ];

      //王涛 ---在这里验证案件是否需要填写补录申请书
      let isPass =  false;
      console.log("查询结果============="+isPass);
      if(obj.docCode === 'docReplenishment'){
        isPass = true ;
      }else {
        isPass =  await this.canAddClearing(this.prevParams.caseUuid);
      }

    if(isPass){

      // 当事人现场确认书判断是否可以添加
      if (obj.docCode === 'docQuickConfirm') {
        caseService.canAddDocQuickConfirm(obj.docUuid, this.prevParams.caseUuid).then(res => {
          if (res.success) {
            this.getToParams(obj);
          } else {
            this.$u.toast(res.msg)
          }
        });
      } else {
        let len = this.caseReaultInfo.docList.length != 0 && this.caseReaultInfo.docList.filter(r => r
          .docCode === obj.docCode).length;
        if (len >= 1 && obj.docCode === 'docLocalePunish') {
          this.$u.toast('《当场行政处罚决定书》已存在，不允许添加多份');
          return;
        } else if (obj.docCode === 'docGoodsApv') {
          // 证据先行登记保存批准书 添加前需调用接口做个验证
          officeService.docRevokeApvCanAdd({ bizUuid: this.prevParams.caseUuid, docUuid: obj.docUuid, }).then((rs) => {
            if (!rs.success) {
              this.$u.toast(rs.msg);
              return;
            } else {
              this.getToParams(obj);
            }
          }).catch(er => {
            console.log(er);
            this.$u.toast(er);
          });
        } else if (obj.docCode === 'docGoodsReg') {
          // 证据先行登记保存通知书 添加前需调用接口做个验证
          officeService.canAdd({ bizUuid: this.prevParams.caseUuid, docUuid: obj.docUuid, }).then((rs) => {
            if (!rs.success) {
              this.$u.toast(rs.msg);
              return;
            } else {
              this.getToParams(obj);
            }
          }).catch(er => {
            console.log(er);
            this.$u.toast(er);
          });
        } else if (obj.docCode === 'docServiceConfirm') {
          // 送达方式确认书 添加前需调用接口做个验证
          officeService.serviceConfirmCanAdd({ bizUuid: this.prevParams.caseUuid, docUuid: obj.docUuid, }).then((rs) => {
            if (!rs.success) {
              this.$u.toast(rs.msg);
              return;
            } else {
              this.getToParams(obj);
            }
          }).catch(er => {
            console.log(er);
            this.$u.toast(er);
          });
        } else if (obj.docCode === 'docLocalePunish') {
          // 当场行政处罚决定书 添加前需调用接口做个验证
          caseService.hasParty({
            caseUuid: this.prevParams.caseUuid,
          }).then(res => {
            if (!res.success) return this.$u.toast('没有录入当事人,请先录入当事人');
            this.getToParams(obj);
          }).catch(er => {
            console.log(er);
            this.$u.toast('没有录入当事人,请先录入当事人');
          });
        } else if (obj.docCode === 'docReplenishment') {
          // 立案报告表 添加前需调用接口做个验证 判断是否能添加 gys 开始 20240410
          console.log('====',this.prevParams.caseUuid,obj.docUuid)
          officeService.canAddDocRegConfirm({ bizUuid: this.prevParams.caseUuid, docUuid: obj.docUuid, }).then((rs) => {
            if (!rs.success) {
              this.$u.toast(rs.msg);
              return;
            } else {
              this.getToParams(obj);
            }
          }).catch(er => {
            console.log(er);
            this.$u.toast(er);
          });
        } // 立案报告表 添加前需调用接口做个验证 判断是否能添加 gys 开始 20240410
        else {
          this.getToParams(obj);
        }
      }
    }

    },


    // 获取跳转路径需要的参数
    getToParams(obj, flag) {
      console.log('obj', obj, flag)
      this.setRouteParam({
        bizUuid: this.prevParams.caseUuid,
        docUuid: obj.docUuid,
        id: flag ? obj.docInsUuid : '',
        type: obj.isFinish ? 'view' : 'add',
        justView: this.justView,
        caseUuid: this.prevParams.caseUuid,
        caseCode: this.prevParams.caseCode,
        titemUuid: this.caseReaultInfo.titemUuid ? this.caseReaultInfo.titemUuid : obj.titemUuid,
        caseType: this.prevParams.handleProc,
        casePropertyRelList: this.baseInfo.casePropertyRelList,
        handleStatus: obj.handleStatus,
        choseType: this.choseType
      });
      console.log('src', this.CASE_DOC_NAME_PATH[obj.docCode].url)
      this.$u.route(this.CASE_DOC_NAME_PATH[obj.docCode].url);

    },
    // 列表点击事件
    async  toDetailOfficial(stage, doc) {

      //王涛 ---在这里验证案件是否需要填写补录申请书
      let isPass = false ;
      if(doc.docCode === 'docReplenishment'){
        isPass = true ;
      }else {
        isPass = await this.canAddClearing(this.prevParams.caseUuid);
      }
      if(isPass){
          this.caseReaultInfo = stage;
          if (doc.docCode == 'docReplenishment' || doc.docCode == 'docLocalePunish') {
            caseService.hasParty({
              caseUuid: this.prevParams.caseUuid,
            }).then(res => {
              if (!res.success) return this.$u.toast('没有录入当事人,请先录入当事人');
              this.getToParams(doc, 'detail');
            }).catch(er => {
              console.log(er);
              // this.$u.toast(er);
              return this.$u.toast('没有录入当事人,请先录入当事人');
            });
          } else {
            this.getToParams(doc, 'detail');
          }
      }
    },
    // 案件基本信息
    caseView() {
      let params = {
        caseCode: this.prevParams.caseCode,
        caseUuid: this.prevParams.caseUuid,
        handleProc: this.baseInfo.handleProc,
        from: "host", // 主办人
        isDocListPage: true,
      }

      if (this.choseType) {
        params.choseType = this.choseType
      }

      this.setRouteParam(params);
      this.$u.route('/pages/case/offline/caseInfo');
    },
    // 文书添加返回操作
    updateBackState(param) {

    },
    // 刷新滑动操作状态
    refreshSwiperStatus() {
      let self = this;
      this.dataList = this.dataList.filter(item => {
        item.docList.filter(doc => {
          self.$set(doc, 'show', false);
        });
        return true;
      });
    },
    // 点击删除 index:列表当前的索引；index1：向左滑动删除的索引
    docRemove(index, index1) {
      let arr = index.split("-");
      let docInsUuid = this.dataList[arr[0]].docList[arr[1]].docInsUuid;
      this.$modal.alert("确定要作废此文书吗？", "提示", () => {
        officeService.checkCanBeDelete({
          docInsUuid: docInsUuid,
        }).then(res => {
          if (res.success) {
            officeService.getDocIns(docInsUuid).then(dr => {
              if (!dr.success) return;
              officeService.isInvalid(dr.bean.configIns.controllerPath,
                docInsUuid).then(valid => {
                  if (valid.success) {
                    this.initDocList();
                  } else {
                    this.$u.toast(valid.msg);
                  }
                })
            })
          }
        });
      }, "确定", true, () => {
        this.refreshSwiperStatus();
      });
    },
    // index 0-1 第一个代表外层list的索引，第二个代表要删除的索引
    offOpen(index) {
      let arr = index.split("-");
      let self = this;
      self.$set(self.dataList[arr[0]].docList[arr[1]], 'show', true);
      self.dataList[arr[0]].docList.map((val, idx) => {
        if (arr[1] != idx) self.$set(self.dataList[arr[0]].docList[idx], 'show', false);
      })
    },
    // 文书图片上传
    submitImage(doc) {
      if (doc.scan || doc.isPicUploadable) {
        this.setRouteParam({
          liddId: doc.docInsUuid,
          isPicUploadable: doc.isPicUploadable,
        });
        this.$u.route('pages/case/official/officialListUploadImage');
      }
    },
    // 查询是否已完成第三方签名
    searchIsSigned(listDocInsUuid) {
      return commonService.isSigned(listDocInsUuid).then(s => {
        return s.success;
      });
    },

    // 生成实名认证地址
    handleShare(doc) {
      this.docIns = doc;
      if (this.baseInfo.noMaster) {
        this.$u.error("当前案件是无主案件");
        return;
      }
      this.$u.loading("检查签名中...");
      commonService.isSigned(doc.docInsUuid).then(s => {
        this.$u.hideLoading();
        if (!s.success) {
          // 再次查询时重置一下结果，改变图标显示
          this.$set(this.docSign, doc.docInsUuid, s.success)
          this.$u.toast(s.msg);
          return;
        }
        this.$u.loading("准备签名中...");
        caseService.getPartyInfoList(this.baseInfo.caseUuid).then(ps => {
          if (!ps.success) {
            this.$u.hideLoading();
            this.$u.error(ps.msg);
            return;
          }
          if (ps.data.length === 0) {
            this.$u.hideLoading();
            // this.$u.error("缺少当事人");
            // return;
          }
          // 处理多个当事人情况，让操作人员选择当前签名的当事人
          this.dsrList = ps.data.map(p => ({ text: p.partyName, partyName: p.partyName, idCard: p.idCard, }));
          if (ps.data.length === 1) {
            this.dsrSelectConfirm(0);
          } else {
            this.$u.hideLoading();
            this.dsrSelectShow = true;
          }
        });
      });
    },
    // 选中当事人
    dsrSelectConfirm(idx) {
      let { partyName, idCard, } = this.dsrList[idx];
      if (!partyName || !idCard) {
        this.$u.hideLoading();
        this.$u.error(!partyName ? "缺少当事人姓名" : "缺少当事人身份证号");
        return;
      }
      // 检查当事人数据是否正确，再调用接口
      commonService.dsrSign(this.docIns.docInsUuid, partyName, idCard).then(dr => {
        this.$u.hideLoading();
        if (!dr.success) {
          this.$u.error(dr.msg);
          return;
        }
        let qrcodeUrl = `${this.signViewUrl}?token=${dr.bean}`;
        // #ifdef H5-WECHAT
        this.$modal.confirm("是否生成二维码给当事人扫码签名？", () => {
          QRCode.toDataURL(qrcodeUrl).then(path => {
            this.qrcodeImg = path;
            this.qrcodeShow = true;
          }).catch(err => {
            this.$u.error(err);
          });
        }, "生成二维码");
        // #endif
        // #ifndef H5-WECHAT
        this.$modal.confirm("是否生成二维码给当事人扫码签名？", () => {
          QRCode.toDataURL(qrcodeUrl).then(path => {
            this.qrcodeImg = path;
            this.qrcodeShow = true;
          }).catch(err => {
            this.$u.error(err);
          });
        }, () => {
          this.$modal.openNewTab(qrcodeUrl);
        }, "生成二维码", "本机签名");
        // #endif
		
      });
    },
    // 验证是否显示发送缴款单按钮
    getLocalePunish() {
      officeService.getLocalePunishById({ localePunishUuid: this.decideUuid, }).then((res) => {
        if (res.success) {
          this.decideDoc = res.bean;
          if (this.decideDoc.payedResult == '-1') {
            this.sendPayIconShow = true;
          }
        } else {
          this.$u.toast(res.msg);
        }
      }).catch((err) => {
        this.$u.toast(err);
      });
    },
    sendEleDeliver(oc) {
      this.eleDoc = oc;
      this.$modal.showLoading('加载中...');
      caseService.getEleDeliverInfo({
        menuCode: undefined,
        docUuid: oc.docUuid,
        bizUuid: this.baseInfo.caseUuid,
        docInsUuid: oc.docInsUuid,
      }).then(res => {
        this.$modal.hideLoading();
        if (res.success) {
          console.log('1111');
          this.deliverEleList = res.bean.list || [];
          this.eleShow = true;
        } else {
          this.$u.toast(res.msg);
          console.log(res.msg);
        }
      }).catch(e => {
        this.$modal.hideLoading();
        this.$u.toast('请求失败:' + e);
        console.log(e);
      });
    },
    eleClose() {
      this.eleShow = false;
      this.initDocList();
    },
    handleSendPay() {
      if (!this.decideDoc.noticeNo) {
        this.$u.toast('缺失缴款单号，无法发送缴款单');
        return;
      }
      this.$modal.confirm('当前缴款单金额：' + this.decideDoc.punishAmt + '元, 确定发送缴款单吗？', () => {
        officeService.sendLocalePunishPay({ localePunishUuid: this.decideUuid, }).then((res) => {
          if (res.success) {
            this.sendPayIconShow = false;
            this.$u.toast('发送缴款成功，缴款人可以通过统一支付平台进行缴款！');
          } else {
            this.$u.toast(res.msg);
          }
        }).catch((err) => {
          this.$u.toast(err);
        });
      });
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../case_common.scss";

.page {
  padding: 0;
}

.official-content {
  .base-info {
    font-size: $font_size_4;
    color: #666;
    margin: 16px 15px;

    .mini-title {
      font-size: .6rem;

      &.gray1 {
        color: #C7C7CC;
      }

      &.gray2 {
        color: #929292;
      }
    }

    .code-content {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      .code-text {
        color: #222;
        // font-size: $font_size_1;
        font-size: 40rpx;
        font-weight: bold;
      }

      .btn-lay {
        margin: 0px 0px;
      }

      .btn-lay::after {
        border: none;
      }
    }

    .addr-lay {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: flex-start;
      align-items: top;
      margin: 16rpx 0rpx;

      view {
        padding: 10rpx 15rpx;
        font-size: $font_size_6;
        background-color: #f2f2f2;
        margin-right: 10rpx;
        border-radius: 8rpx;
      }
    }

    .medium-title {
      font-size: $font_size_2;
      margin: 20px 0px 8px;
      font-weight: bold;
      color: #222;
    }

    .bottom-space {
      margin-bottom: 20px;
    }
  }

  .official-info {
    margin: 16px 15px;

    .off-info-item {
      margin: 20px 0px 8px;

      .off-info-title {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        font-size: $font_size_6;
        color: #2979ff;

        .title-text {
          color: #222;
          font-size: $font_size_2;
          font-weight: bold;
        }
      }

      .off-info-content {
        padding: 20px 0px;
        border-bottom: 1px solid #e4e7ed;

        .off-title {
          display: inline-block;
          padding: 0px 5px;
        }

        .off-date {
          padding: 8px 0px 0px 24px;
          color: #929292;
        }

      }
    }
  }
}

.off-tb {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
}

.sub-img {
  display: flex;
  align-items: center;
  font-size: 12px;

  .u-green {
    height: 18px;
    line-height: 18px;
    color: #41C087;
    padding-left: 5px;
  }

  .u-gray {
    height: 18px;
    line-height: 18px;
    color: gray;
    padding-left: 5px;
  }
}

.reason-lay {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: top;
  margin: 20rpx 0rpx;
  font-size: .7rem;
  color: #565656;

  view:first-child {
    color: #999999;
  }
}

.right-box {
  margin: auto 0;
}

.text-sty {
  color: $u_type_primary;
}

.qrcodeContainer {
  text-align: center;

  img {
    width: 95%;
  }

  p {
    font-size: 18px;
    font-weight: 600;
    color: #333;
  }
}
</style>
